package net.lastcoder.ifserver.module;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.HashMap;

/**模块管理器，本身不是一个模块，是一个必须组件<p>
 * 模块名可以在{@link ModuleNames}中找到
 * auth: WenYF
 * date: 2016/10/22
 */
public class ModuleManager {
    public static final Logger Log = LoggerFactory.getLogger(ModuleManager.class);

    private static class SingletonHolder {
        private static ModuleManager instance = new ModuleManager();
    }

    public static ModuleManager getInstance() {
        return SingletonHolder.instance;
    }

    private HashMap<String, Module> modules;

    public ModuleManager() {
        modules = new HashMap<>();
    }

    public Module getModule(String name) {
        return modules.get(name);
    }

    public void removeModule(String name) {
        modules.remove(name);
    }

    public void removeModule(Module module) {
        modules.remove(module.getName());
    }

    public void addModule(Module module) {
        modules.put(module.getName(), module);
    }

    public Collection<Module> getModules() {
        return modules.values();
    }

}
